/*

 $Id: nvclib_core.h 6 2009-10-15 06:30:15Z alex.mobilebi $
 $Date: 2009-10-15 06:30:15 +0000 (Thu, 15 Oct 2009) $
 $Author: alex.mobilebi $
 $Revision: 6 $

 Copyright(C) 2009 Alex Lee(alex@mobilebi.com)

 */

#ifndef NVC_LIB_CORE_H
#define NVC_LIB_CORE_H
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <time.h>
#include <sys/time.h>
#include <string.h>
#include <pthread.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "nvclib.h"

struct nvcBoard
{
	unsigned char active;// 0 - unactive; 1 - active
	int pci; // handler of PCI device file
	int local;//handler of Local device file
};
struct nvcPort
{
	unsigned char active; // 0 - unactive; 1 - active
	unsigned char board_id;
	unsigned char port_id;
	unsigned char port_type;
	unsigned char port_mode;
	unsigned char frame_type;
	unsigned char code_type;
	unsigned char impedance;
};

struct nvcLink
{
	unsigned char active;
	unsigned char port;
	unsigned short link;
	unsigned char start_ts; //start time slot
	unsigned char ts_num;   //number of time slot assigned to channel	
};

unsigned char is_valid_port_config(const struct port_config conf);
void add_link_config(const struct link_config conf);
unsigned char is_valid_link_config(const struct link_config conf);
unsigned char is_link_full(unsigned char board);
void add_port_config(const struct port_config conf);
unsigned char is_config(void);
unsigned char is_port_configured(unsigned char board, unsigned char port);
unsigned char is_link_configured(unsigned char board, unsigned char port);
unsigned char is_board_configured(unsigned char board);
int read_data(unsigned char * buff, const unsigned int size);
int open_board(void);
void open_one_board(unsigned char board);
unsigned char is_any_board_opened(void);
unsigned char is_one_board_opened(unsigned char board);
void init_board(void);
void init_one_board(unsigned char board);
void close_board(void);
void close_one_board(unsigned char board);
void start_board(void);
void start_one_board(unsigned char board);
void stop_board(void);
void stop_one_board(unsigned char board);
unsigned char is_initialized(void);
void init_ds31256(unsigned char board);
unsigned char is_running(void);
void init_local(int fd);
void reset_ds31256(int fd);
void zero_reg_ram(int fd);
void init_layer1(unsigned char board);
void set_port_type(int fd, unsigned char port, unsigned char port_mode);
void set_port_ts(unsigned char board, unsigned char port);
void init_hdlc(unsigned char board);
void set_hdlc_crc_mode(int fd, unsigned char channel);
void init_fifo(unsigned char board);
void init_dma(unsigned char board);
void start_ds31256(unsigned char board);
void start_ds26519(unsigned char board);
void stop_ds31256(int board);
void stop_ds26519(int board);
int init_ds26519(unsigned char board);
void reset_ds26519(int fd);
void init_global(int fd);
void init_framer(unsigned char board);
void init_liu(unsigned char board);
void init_bert(void);
void dump_ds31256(FILE * fptr, char dev);
void dump_ds26519(FILE * fptr, char dev);
unsigned short read_reg(const unsigned short addr);
unsigned short read_ind_reg(const unsigned short addr, const unsigned short index);
void write_reg(const unsigned short addr, const unsigned short data);
unsigned short read_reg8(const unsigned short addr);
unsigned short write_reg8(const unsigned short addr, const unsigned short data);
#endif